<?php

class Twitter {

	const JSON = 'json';
	const RSS = 'rss';
	const XML = 'xml';
	const ATOM = 'atom';

	public $cache = true;

	public $type;
	public $lastUrl;

	public function __construct($type) {
		$this->type = $type;
	}

	public function getUserTimeline($user, $callback, $count) {
		$url = sprintf("http://twitter.com/statuses/user_timeline/%s.%s?callback=%s&count=%d", $user, $this->type, $callback, $count);
		$this->lastUrl = $url;
		return self::getUrl($url);
	}

//	public static function query( $function, array $params ) {
//		
//	}

	public static function getUrl($url) {
		if (function_exists('curl_init')) {
			$ch = curl_init();
			curl_setopt_array($ch, array(
				CURLOPT_URL => $url,
				CURLOPT_HEADER => 0,
				CURLOPT_RETURNTRANSFER => true
			));

			return curl_exec($ch);
		} else {
			$handle = fopen($url, "r");
			$contents = stream_get_contents($handle);
			fclose($handle);
		}
	}

//	public_timeline
//	Returns the 20 most recent statuses from non-protected users who have set a custom user icon.  Does not require authentication.
//	URL: http://twitter.com/statuses/public_timeline.format
//	Formats: xml, json, rss, atom 
//		* since_id.  Optional.  Returns only public statuses with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/statuses/public_timeline.xml?since_id=12345
//	public function publicTimeline( $since_id = null )
//	{
//	
//	}

//	friends_timeline
//	Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user and that user's friends.  It's also possible to request another user's friends_timeline via the id parameter below.
//	URL: http://twitter.com/statuses/friends_timeline.format
//	Formats: xml, json, rss, atom
//		* id.  Optional.  Specifies the ID or screen name of the user for whom to return the friends_timeline.  Ex: http://twitter.com/statuses/friends_timeline/12345.xml or http://twitter.com/statuses/friends_timeline/bob.json.
//		* since.  Optional.  Narrows the returned results to just those statuses created after the specified HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in your HTTP request.  Ex: http://twitter.com/statuses/friends_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* page. Optional.  Gets the 20 next most recent statuses from the authenticating user and that user's friends.  Ex: http://twitter.com/statuses/friends_timeline.rss?page=3 TEMPORARILY DISABLED
//	public function friendsTimeline( $id = null, $since = null, $page = null )
//	{
//	
//	}

//	user_timeline
//	Returns the 20 most recent statuses posted in the last 24 hours from the authenticating user.  It's also possible to request another user's timeline via the id parameter below.
//	URL: http://twitter.com/statuses/user_timeline.format
//	Formats: xml, json, rss, atom
//		* id.  Optional.  Specifies the ID or screen name of the user for whom to return the friends_timeline.  Ex: http://twitter.com/statuses/user_timeline/12345.xml or http://twitter.com/statuses/user_timeline/bob.json.
//		* count.  Optional.  Specifies the number of statuses to retrieve.  May not be greater than 20 for performance purposes.  Ex: http://twitter.com/statuses/user_timeline?count=5 
//		* since.  Optional.  Narrows the returned results to just those statuses created after the specified HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in your HTTP request.  Ex: http://twitter.com/statuses/user_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/statuses/user_timeline.xml?since_id=12345
//	public function userTimeline( $id = null, $count = null, $since = null, $since_id = null )
//	{
//		$url = 'http://twitter.com/statuses/user_timeline';
//
//		if( $id ) $url .= '/' . $id;
//		
//		$url .= $this->type;
//		
//		if( $count ) 
//		
//		//?callback=$callback&count=$count";
//		$this->lastUrl = $url;
//		return Twitter::getUrl( $url );
//	}

//	show
//	Returns a single status, specified by the id parameter below.  The status's author will be returned inline.
//	URL: http://twitter.com/statuses/show/id.format
//	Formats: xml, json
//		* id.  Required.  The numerical ID of the status you're trying to retrieve.  Ex: http://twitter.com/statuses/show/123.xml 
//	public function show( $id )
//	{
//	
//	}
	
//	update
//	Updates the authenticating user's status.  Requires the status parameter specified below.  Request must be a POST.
//	URL: http://twitter.com/statuses/update.format
//	Formats: xml, json.  Returns the posted status in requested format when successful.
//		* status.  Required.  The text of your status update.  Be sure to URL encode as necessary.  Must not be more than 160 characters and should not be more than 140 characters to ensure optimal display.
//	public function update( $status )
//	{
//	
//	}
	
//	replies
//	Returns the 20 most recent replies (status updates prefixed with @username posted by users who are friends with the user being replied to) to the authenticating user.  Replies are only available to the authenticating user; you can not request a list of replies to another user whether public or protected.
//	URL: http://twitter.com/statuses/replies.format
//	Formats: xml, json, rss, atom
//		* page.  Optional. Retrieves the 20 next most recent replies.  Ex: http://twitter.com/statuses/replies.xml?page=3
//		* since.  Optional.  Narrows the returned results to just those replies created after the specified HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in your HTTP request.  Ex: http://twitter.com/statuses/replies.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/statuses/replies.xml?since_id=12345
//	public function replies( $page = null, $since = null, $since_id = null )
//	{
//	
//	}
	
//	destroy
//	Destroys the status specified by the required ID parameter.  The authenticating user must be the author of the specified status.
//	URL: http://twitter.com/statuses/destroy/id.format
//	Formats: xml, json
//		* id.  Required.  The ID of the status to destroy.  Ex: http://twitter.com/statuses/destroy/12345.json or http://twitter.com/statuses/destroy/23456.xml
//	public function destroy( $id )
//	{
//	
//	}

//	User Methods
//
//	friends
//	Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.  It's also possible to request another user's recent friends list via the id parameter below. 
//	URL: http://twitter.com/statuses/friends.format
//	Formats: xml, json
//		* id.  Optional.  The ID or screen name of the user for whom to request a list of friends.  Ex: http://twitter.com/statuses/friends/12345.json or http://twitter.com/statuses/friends/bob.xml
//		* page.  Optional. Retrieves the next 100 friends.  Ex: http://twitter.com/statuses/friends.xml?page=2 
//		* lite. Optional.  Prevents the inline inclusion of current status.  Must be set to a value of true.  Ex: http://twitter.com/statuses/friends.xml?lite=true
//		* since.  Optional.  Narrows the returned results to just those friendships created after the specified HTTP-formatted date.  The same behavior is available by setting an If-Modified-Since header in your HTTP request.  Ex: http://twitter.com/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT 
//	public function friends( $id = null, $page = null, $lite = null, $since = null )
//	{
//	
//	}
	
//	followers
//	Returns the authenticating user's followers, each with current status inline. 
//	URL: http://twitter.com/statuses/followers.format
//	Formats: xml, json
//		* page.  Optional. Retrieves the next 100 followers.  Ex: http://twitter.com/statuses/followers.xml?page=2
//		* lite. Optional.  Prevents the inline inclusion of current status.  Must be set to a value of true.  Ex: http://twitter.com/statuses/followers.xml?lite=true
//	public function followers( $page = null, $lite = null )
//	{
//	
//	}
	
//	featured
//	Returns a list of the users currently featured on the site with their current statuses inline.
//	URL: http://twitter.com/statuses/featured.format 
//	Formats: xml, json
//	public function featured()
//	{
//	
//	}
	
//	show
//	Returns extended information of a given user, specified by ID or screen name as per the required id parameter below.  This information includes design settings, so third party developers can theme their widgets according to a given user's preferences.
//	URL: http://twitter.com/users/show/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen name of a user.  Ex: http://twitter.com/users/show/12345.json or http://twitter.com/users/show/bob.xml
//		* email. Optional.  The email address of a user.  Ex: http://twitter.com/users/show.xml?email=test@example.com
//	Notes:
//		* If you are trying to fetch data for a user who is only giving updates to friends, the returned text will be "You are not authorized to see this user." 
//
//	Direct Message Methods
//
//	direct_messages
//	Returns a list of the 20 most recent direct messages sent to the authenticating user.  The XML and JSON versions include detailed information about the sending and recipient users.
//	URL: http://twitter.com/direct_messages.format
//	Formats: xml, json, rss, atom 
//		* since.  Optional.  Narrows the resulting list of direct messages to just those sent after the specified HTTP-formatted date.  The same behavior is available by setting the If-Modified-Since parameter in your HTTP request.  Ex: http://twitter.com/direct_messages.atom?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* since_id.  Optional.  Returns only direct messages with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/direct_messages.xml?since_id=12345
//		* page.  Optional. Retrieves the 20 next most recent direct messages.  Ex: http://twitter.com/direct_messages.xml?page=3
//
//	sent
//	Returns a list of the 20 most recent direct messages sent by the authenticating user.  The XML and JSON versions include detailed information about the sending and recipient users.
//	URL: http://twitter.com/direct_messages/sent.format
//	Formats: xml, json
//		* since.  Optional.  Narrows the resulting list of direct messages to just those sent after the specified HTTP-formatted date.  The same behavior is available by setting the If-Modified-Since parameter in your HTTP request.  Ex: http://twitter.com/direct_messages/sent.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* since_id.  Optional.  Returns only sent direct messages with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/direct_messages/sent.xml?since_id=12345
//		* page.  Optional. Retrieves the 20 next most recent direct messages sent.  Ex: http://twitter.com/direct_messages/sent.xml?page=3
//
//	new
//	Sends a new direct message to the specified user from the authenticating user.  Requires both the user and text parameters below.  Request must be a POST.  Returns the sent message in the requested format when successful.
//	URL: http://twitter.com/direct_messages/new.format
//	Formats: xml, json  
//		* user.  Required.  The ID or screen name of the recipient user.
//		* text.  Required.  The text of your direct message.  Be sure to URL encode as necessary, and keep it under 140 characters.  
//
//	destroy
//	Destroys the direct message specified in the required ID parameter.  The authenticating user must be the recipient of the specified direct message.
//	URL: http://twitter.com/direct_messages/destroy/id.format
//	Formats: xml, json
//		* id.  Required.  The ID of the direct message to destroy.  Ex: http://twitter.com/direct_messages/destroy/12345.json or http://twitter.com/direct_messages/destroy/23456.xml
//
//
//	Friendship Methods
//
//	create
//	Befriends the user specified in the ID parameter as the authenticating user.  Returns the befriended user in the requested format when successful.  Returns a string describing the failure condition when unsuccessful.
//	URL: http://twitter.com/friendships/create/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen name of the user to befriend.  Ex: http://twitter.com/friendships/create/12345.json or http://twitter.com/friendships/create/bob.xml
//
//	destroy
//	Discontinues friendship with the user specified in the ID parameter as the authenticating user.  Returns the un-friended user in the requested format when successful.  Returns a string describing the failure condition when unsuccessful.
//	URL: http://twitter.com/friendships/destroy/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen name of the user with whom to discontinue friendship.  Ex: http://twitter.com/friendships/destroy/12345.json or http://twitter.com/friendships/destroy/bob.xml
//
//	exists
//	Tests if friendship exists between the two users specified in the parameter specified below.
//	URL: http://twitter.com/friendships/exists.format
//	Formats: xml, json, none
//		* user_a.  Required.  The ID or screen_name of the first user to test friendship for.
//		* user_b.  Required.  The ID or screen_name of the second user to test friendship for.
//		* Ex: http://twitter.com/friendships/exists.xml?user_a=alice&user_b=bob
//
//
//	Account Methods
//
//	verify_credentials
//	Returns an HTTP 200 OK response code and a format-specific response if authentication was successful.  Use this method to test if supplied user credentials are valid with minimal overhead.
//	URL: http://twitter.com/account/verify_credentials.format
//	Formats: text (returned when no format is specified), xml, json
//
//	end_session
//	Ends the session of the authenticating user, returning a null cookie.  Use this method to sign users out of client-facing applications like widgets.
//	URL: http://twitter.com/account/end_session
//	Formats: N/A
//
//	archive
//	Returns 80 statuses per page for the authenticating user, ordered by descending date of posting.  Use this method to rapidly export your archive of statuses.
//	URL: http://twitter.com/account/archive.format
//	Formats: xml, json
//		* page.  Optional. Retrieves the 80 next most recent statuses.  Ex: http://twitter.com/account/archive.xml?page=2
//		* since.  Optional.  Narrows the resulting list of statuses to just those sent after the specified HTTP-formatted date.  The same behavior is available by setting the If-Modified-Since parameter in your HTTP request.  Ex: http://twitter.com/account/archive.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
//		* since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) the specified ID.  Ex: http://twitter.com/account/archive.xml?since_id=12345
//
//	update_location
//	Updates the location attribute of the authenticating user, as displayed on the side of their profile and returned in various API methods.  Works as either a POST or a GET.
//	URL: http://twitter.com/account/update_location.format
//	Formats: xml, json
//		* location.  Required.  The location of the user.  Please note this is not normalized, geocoded, or translated to latitude/longitude at this time.  Ex: http://twitter.com/account/update_location.xml?location=San%20Francisco
//
//	update_delivery_device
//	Sets which device Twitter delivers updates to for the authenticating user.  Sending none as the device parameter will disable IM or SMS updates.
//	URL: http://twitter.com/account/update_delivery_device.format
//	Formats: xml, json
//		* device.  Required.  Must be one of: sms, im, none.  Ex: http://twitter.com/account/update_delivery_device?device=im
//
//
//	Favorite Methods
//
//	favorites
//	Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter in the requested format. 
//	URL: http://twitter.com/favorites.format
//	Formats: xml, json, rss, atom
//		* id.  Optional.  The ID or screen name of the user for whom to request a list of favorite statuses.  Ex: http://twitter.com/favorites/bob.json or http://twitter.com/favorites/bob.rss
//		* page.  Optional. Retrieves the 20 next most recent favorite statuses.  Ex: http://twitter.com/favorites.xml?page=3 
//
//	create
//	Favorites the status specified in the ID parameter as the authenticating user.  Returns the favorite status when successful.
//	URL: http://twitter.com/favorites/create/id.format
//	Formats: xml, json
//		* id.  Required.  The ID of the status to favorite.  Ex: http://twitter.com/favorites/create/12345.json or http://twitter.com/favorites/create/45567.xml
//
//	destroy
//	Un-favorites the status specified in the ID parameter as the authenticating user.  Returns the un-favorited status in the requested format when successful.
//	URL: http://twitter.com/favorites/destroy/id.format
//	Formats: xml, json
//		* id.  Required.  The ID of the status to un-favorite.  Ex: http://twitter.com/favorites/destroy/12345.json or http://twitter.com/favorites/destroy/23456.xml 
//
//
//	Notification Methods
//
//	follow
//	Enables notifications for updates from the specified user to the authenticating user.  Returns the specified user when successful.
//	URL: http://twitter.com/notifications/follow/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen name of the user to follow.  Ex:  http://twitter.com/notifications/follow/12345.xml or http://twitter.com/notifications/follow/bob.json  
//
//	leave
//	Disables notifications for updates from the specified user to the authenticating user.  Returns the specified user when successful.
//	URL: http://twitter.com/notifications/leave/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen name of the user to leave.  Ex:  http://twitter.com/notifications/leave/12345.xml or http://twitter.com/notifications/leave/bob.json 
//
//
//	Block Methods
//
//	create
//	Blocks the user specified in the ID parameter as the authenticating user.  Returns the blocked user in the requested format when successful.  You can find out more about blocking in the Twitter Support Knowledge Base.
//	URL: http://twitter.com/blocks/create/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen_name of the user to block.  Ex: http://twitter.com/blocks/create/12345.json or http://twitter.com/blocks/create/bob.xml
//
//	destroy
//	Un-blocks the user specified in the ID parameter as the authenticating user.  Returns the un-blocked user in the requested format when successful.
//	URL: http://twitter.com/blocks/destroy/id.format
//	Formats: xml, json
//		* id.  Required.  The ID or screen_name of the user to un-block.  Ex: http://twitter.com/blocks/destroy/12345.json or http://twitter.com/blocks/destroy/bob.xml 

}
